package com.elong.businesstravel.entitys;

import java.io.IOException;
import java.io.Serializable;
import java.util.Calendar;

import android.content.Context;

import com.android.support.jhf.utils.DateUtils;
import com.elong.businesstravel.ELongBusinessTravelApplication;
import com.elong.businesstravel.protocol.ProtocolDef;

/**
 * 酒店搜索条件类
 * 
 * @author lenovo
 * 
 */
public class HotelSearchCondition implements Serializable {

	public City mSearchConditionCity;
	public Poi mSearchConditionPoi;
	public int mSearchConditionPriceValuePosition;
	public String mSearchConditionDate;
	public String mSearchConditionDays;

	public String piloting;

	public String chainId;
	// public String bussinesId;
	// public String districtsId;
	// public Double lat;
	// public Double lng;
	public String keyword;
	public Integer pageSize = ProtocolDef.PAGE_SIZE;
	public Integer page = 1;
	public Integer sorts = 0;
	/**0 全部， 1预付可抵扣酒店*/
	public Integer product = 0;
	/**1 显示满房 0 不显示满房*/
	public Integer isfull = 1;
	public Integer uid;
	public String deviceId;
	public String token;

	public String getStartDate() {
		String startDate = null;
		try {
			startDate = DateUtils.dateFormat(DateUtils.getDateMillis(
					mSearchConditionDate, "yyyy-MM-dd (E)"), "yyyyMMdd");
		} catch (Exception e) {

		}

		return startDate;
	}

	public String getStartDateFormat(String pattern) {
		String startDate = null;
		try {
			startDate = DateUtils.dateFormat(DateUtils.getDateMillis(
					mSearchConditionDate, "yyyy-MM-dd (E)"), pattern);
		} catch (Exception e) {

		}

		return startDate;
	}

	public long getStartDateMillis(){
		long startDate = 0L;
		try {
			startDate = DateUtils.getDateMillis(
					mSearchConditionDate, "yyyy-MM-dd (E)");
		} catch (Exception e) {
		}
		return startDate;
	}
	
	public long getEndDateMillis(){
		long endDate = 0L;
		try {
			Calendar calendar = Calendar.getInstance();
			calendar.setTimeInMillis(DateUtils.getDateMillis(
					mSearchConditionDate, "yyyy-MM-dd (E)"));
			calendar.add(Calendar.DAY_OF_MONTH, Integer
					.parseInt(mSearchConditionDays.substring(0,
							mSearchConditionDays.length() - 1)));
			endDate = calendar.getTimeInMillis();
		} catch (Exception e) {
		}
		return endDate;
	}
	
	public String getEndDate() {
		String endDate = null;
		try {
			Calendar calendar = Calendar.getInstance();
			calendar.setTimeInMillis(DateUtils.getDateMillis(
					mSearchConditionDate, "yyyy-MM-dd (E)"));
			calendar.add(Calendar.DAY_OF_MONTH, Integer
					.parseInt(mSearchConditionDays.substring(0,
							mSearchConditionDays.length() - 1)));
			endDate = DateUtils.dateFormat(calendar.getTimeInMillis(),
					"yyyyMMdd");
		} catch (Exception e) {

		}

		return endDate;
	}

	public String getMinPrice(Context context) {
		ELongBusinessTravelApplication application = (ELongBusinessTravelApplication) context
				.getApplicationContext();
		String minPrice = null;

		if (0 == mSearchConditionPriceValuePosition) {
			// 价格不限
		} else {
			// 价钱
			// if (mSearchConditionPriceValuePosition <= 5) {
			String priceString = application.mPriceLevelValue[mSearchConditionPriceValuePosition];
			if (priceString.split("~").length > 1) {
				minPrice = priceString.split("~")[0];
			}
			// maxpPrice = priceString.split("~")[1];
			// } else {
			// 星级
			// star =
			// mApplication.mPriceLevelValue[mSearchConditionPriceValuePosition];
			// }
		}

		return minPrice;
	}

	public String getMaxPrice(Context context) {

		ELongBusinessTravelApplication application = (ELongBusinessTravelApplication) context
				.getApplicationContext();
		String maxPrice = null;

		if (0 == mSearchConditionPriceValuePosition) {
			// 价格不限
		} else {
			// 价钱
			// if (mSearchConditionPriceValuePosition <= 5) {
			String priceString = application.mPriceLevelValue[mSearchConditionPriceValuePosition];
			// minPrice = priceString.split("~")[0];
			if (priceString.split("~").length > 1) {
				maxPrice = priceString.split("~")[1];
			}
			// } else {
			// 星级
			// star =
			// mApplication.mPriceLevelValue[mSearchConditionPriceValuePosition];
			// }
		}

		return maxPrice;

	}

	public String getStar(Context context) {

		ELongBusinessTravelApplication application = (ELongBusinessTravelApplication) context
				.getApplicationContext();
		String star = null;

		if (0 == mSearchConditionPriceValuePosition) {
			// 价格不限
		} else {
			// 价钱
			// if (mSearchConditionPriceValuePosition <= 5) {
			// String priceString =
			// application.mPriceLevelValue[mSearchConditionPriceValuePosition];
			// minPrice = priceString.split("~")[0];
			// maxPrice = priceString.split("~")[1];
			// } else {
			// 星级
			String priceString = application.mPriceLevelValue[mSearchConditionPriceValuePosition];
			if (priceString.split("~").length == 1) {
				star = application.mPriceLevelValue[mSearchConditionPriceValuePosition];
			}
			// }
		}

		return star;

	}

	/**
	 * 返回住几晚，返回的是数字
	 * 
	 * @return
	 */
	public int getLiveDays() {
		int result = 0;
		try {
			result = Integer.parseInt(mSearchConditionDays.substring(0,
					mSearchConditionDays.length() - 1));
		} catch (Exception e) {
		}
		return result;
	}

}
